class Solution {
public:
    string addBinary(string a, string b) {
        if(a.size() > b.size())
            swap(a, b); // 让b是长的
 
        string ret = "" ;
        int val = 0, carry = 0;
        for(int i = b.size()-1, j = a.size()-1; i >= 0 ; --i)
        {
            if(j >= 0)
                val = (a[j--] - '0') + (b[i] - '0') + carry;
            else
                val = (b[i] - '0') + carry;
            carry = val / 2;
            ret += ((val % 2) + '0');
        }
        if(carry)
            ret += (carry + '0');
        reverse(ret.begin(), ret.end());
        return ret;
    }
};